package com.youth.mapper;

import com.youth.entity.po.Area;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

/**
 * @ClassName IAreaMapper
 * @Description: TODO
 * @Author yjwu
 * @Date 2019/10/21 22:22
 **/
@Mapper
public interface IAreaMapper {

    @Insert("INSERT INTO t_area (name,country_id,status,create_time,update_time) " +
            "VALUES(#{name},#{countryId},#{status},#{createTime},#{updateTime})")
    @Options(useGeneratedKeys = true, keyColumn = "id")
    Integer add(Area area);

    @Update("UPDATE t_area SET status=#{status},update_time=#{updateTime} WHERE id=#{id}")
    Integer deleteById(@Param("id") int id, @Param("status") int status, @Param("updateTime") Date updateTime);

    @Update("UPDATE t_area SET name=#{name},country_id=#{countryId},update_time=#{updateTime} WHERE id=#{id}")
    Integer updateById(Area area);


    @Select("SELECT * FROM t_area WHERE id=#{id}")
    Area findById(@Param("id") int id);

    @Select("<script>" +
            "SELECT * FROM t_area " +
            "<if test='status != null'> " + " WHERE status=#{status} " +
            "</if>" +
            "</script>")
    List<Area> findAllByStatus(@Param("status") Integer status);

}
